#! /bin/bash
Dpath=""
file=""
lock=""
sLock=""
lLock=""
uLock=""
theme=""
Dtheme="$HOME/.config/awesome/themes"

if ! [ -f "$Dtheme/$1" ]; then
    echo '$1' theme does not exist. List of available themes:
    ls -1 $Dtheme
    exit
else
    theme=$1
    Dpath=$Dtheme/theme/wallpaper
    file=$Dpath/wall.png
    lock=$Dpath/lock_
    sLock="$lock"short.png
    lLock="$lock"long.png
    uLock="$lock"up.png
fi

if ! [ -f $2 ]; then
    echo File '$2' does not exist
    exit
else
    shift
fi

echo converting to png...
convert $1 $file && echo SUCCESS || (echo FAILED ; exit)

echo bluring image...
convert $file -blur 5x10 $sLock && echo SUCCESS || (echo FAILED ; exit)

echo making wide horizontal image...
convert +append {,}$sLock $lLock && echo SUCCESS || (echo FAILED ; exit)

echo making wide vertical image...
convert -append {,}$sLock $uLock && echo SUCCESS || (echo FAILED ; exit)

echo Making a file with full path to pics...
echo $file  >  $lock
echo $sLock >> $lock
echo $lLock >> $lock
echo $uLock >> $lock

if [ $3 = "sddm" ] 2> /dev/null; then
    echo Copy to sddm theme...
    doas cp $file /usr/share/sddm/themes/sugar-candy/Backgrounds && echo SUCCESS || (echo FAILED ; exit)
fi

echo Done
